import { resolveComponent, h } from 'vue'

const FIcon = (props) => {
  const { icon, size = 16, color, type = 'svg' } = props
  // type svg or element，分别是svgicon和饿了么自带icon
  if (type === 'svg') {
    const iconName = `#${icon}`
    return (
      <svg style={{ width: size + 'px', height: size + 'px', fill: 'currentColor', verticalAlign: 'middle' }}>
        <use xlink:href={iconName} fill={color} />
      </svg>
    )
  } else {
    return (
      <el-icon size={size} color={color}>
        {h(resolveComponent(icon))}
      </el-icon>
    )
  }
}

export default FIcon
